/**
 * @author LYJ
 * Created by Administrator on 2018/3/6 0006.
 */
function FoodTypeTransferForm(option) {
    BootstrapValidateBaseForm.call(this,option.$modal.find("form"),option.$error);
    var This = this;
    this.table = option.table;
    this.$modal = option.$modal;

    this.clear = function () {

    };

    this.init = {
        start: function () {
            This.$error.hintModal();
            This.$modal.hintModal({backdrop:true});
            if (This.type == null || This.type == "add") {
                this.transfer();
            }
            This.element("back").bind("click",function () {
                This.$modal.hintModal().hide();
            });
            This.element("submit").bind("click",function () {
                This.run();
            });

            /** 隐藏modal时事件 */
            This.$modal.on('hide.bs.modal', function () {
                This.clear();
            });
        },
        transfer: function () {
            This.$form.bootstrapValidator({
                fields: {
                    targetTypeId: {
                        validators: {
                            callback: {
                                message: '必须选择一个类型',
                                callback: function (value, validator) {
                                    return value != 0;
                                }
                            }
                        }
                    }
                }
            });
        }
    };

    this.ajaxForm = {
        start: function () {
            This.validate();
            setTimeout(function () {
                if(!This.$form.data("bootstrapValidator").isValid()){
                    return;
                }

                if (This.type == null || This.type == "transfer") {
                    This.ajaxForm.transfer();
                }
            },500);
        },
        transfer: function () {
            This.element("submit").attr("disabled",true);
            This.$form.ajaxSubmit({
                type: "post",
                url: "foodtype/transfer",
                success:function (data) {
                    if(data["recode"] == "0"){
                        This.$modal.hintModal().hide();
                        This.table.tableBar.bootstrapTable("refresh");
                        This.element("submit").attr("disabled",false);
                        This.$error.hintModal().showError("转移成功",1000);
                    }else{
                        This.$error.hintModal().showError(data["error"],1000);
                    }
                    This.element("submit").attr("disabled",false);
                }
            });
        }
    }
}(function () {
    var Super = function(){};
    Super.prototype = BootstrapValidateBaseForm.prototype;
    FoodTypeForm.prototype = new Super();
})();